package com.china08.yxyapi.api.schwebsite.appdownload;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;

@CrossOrigin
@RestController
public class SwsAppDownloadUrlController extends YxyApiBaseController {

    protected static final String HRB = "http://www.hrbeduy.com/module/home/download.html";
    protected static final String BJ = "http://www.91yunxiao.com/module/home/download.html";

    @RequestMapping(value = "/api_yw/schwebsite/appdownload/url", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel process(HttpServletRequest request, HttpServletResponse response) {
        RespModel model = new RespModel();
        String domainName = getDomainName(request);
        Assert.isTrue(StringUtils.isNotBlank(domainName), "域名为空");
        String url = "";
        // ##
        // 哈尔滨旧域名
        if (domainName.contains("hrbeduy")) {
            url = HRB;
        }
        // ##
        // 哈尔滨新域名
        else if (domainName.contains("hrbeduy")) {
            url = HRB;
        }
        // ##
        // 云校
        else if (domainName.contains("91yunxiao")) {
            url = BJ;
        } else if (domainName.contains("91eduy")) {
            url = BJ;
        }
        // 其他云校
        else {
            url = BJ;
        }
        model.url = url;
        return model;
    }

    protected static class RespModel {

        // 下载地址
        public String url;

    }

}
